const ip =
    /^((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([1-9]))\.(((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([0-9]))\.){2}((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([1-9]))$/
const mac = /^[A-Fa-f0-9]{12}$/
const telNum = /(^1[3456789]\d{9}$)|(^4\d{9}$)|(^8\d{7,9}$)|(^9\d{4}$)/ // 校验1、4、8、9开头的电话号码
// 正浮点数，最多4位小数
const FLOAT_POSITION_4 = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,4})?$/
const FLOAT_POSITION_8 = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,8})?$/
const isIp = val => {
    return ip.test(val)
}
const isMac = val => {
    return mac.test(val)
}

const isTelNum = val => {
    return telNum.test(val)
}
const validatorTel = (rule, value, callback) => {
    return isTelNum(value)
}
const isFloat = val => {
    console.log('FLOAT_POSITION_8.test(val)', val, FLOAT_POSITION_8.test(val))
    return FLOAT_POSITION_8.test(val)
}

module.exports = {
    isIp,
    isMac,
    isTelNum,
    validatorTel,
    isFloat,
}
